package com.example.commonlib.commonutil;

import android.view.View;

/**
 * Created by aiyou on 2017/6/29.
 */
//屏幕边界判断
public class TouchUtil {

    public static int[] isOutOfScreenEage(int x,int y,View view) {
        int[] loaction = new int[2];
        loaction[0] = caluIsXOut(x,view);
        loaction[1] = cluIsYOut(y,Util.getStatusBarHei(),view);
        //MLog.e("outEage:"+"y:"+y+" top:"+view.getTop()+" eage:"+(Util.getScreenHeight(App.INSTANCE) - view.getHeight() - view.getTop()));
        return loaction;
    }

    public static int[] isOutOfScreenEageNoStatusBar(int x,int y,View view){
        int[] loaction = new int[2];
        loaction[0] = caluIsXOut(x,view);
        loaction[1] = cluIsYOut(y,0,view);
        //MLog.e("outEage:"+"y:"+y+" top:"+view.getTop()+" eage:"+(Util.getScreenHeight(App.INSTANCE) - view.getHeight() - view.getTop()));
        return loaction;
    }

    private static int caluIsXOut(int x,View view){
        int resultX;
        if (x < -view.getLeft()) {
            resultX = -view.getLeft();
        } else if (x > Util.getScreenWidth(App.INSTANCE) - view.getWidth()-view.getLeft()) {
            resultX = Util.getScreenWidth(App.INSTANCE) - view.getWidth()-view.getLeft();
        } else {
            resultX = x;
        }
        return resultX;
    }

    private static int cluIsYOut(int y,int statusBarHeight,View view){
        int resultY;
        if (y < -view.getTop()) {
            resultY = -view.getTop();
        } else if (y > Util.getScreenHeight(App.INSTANCE) - view.getHeight() - view.getTop() - statusBarHeight) {
            resultY = Util.getScreenHeight(App.INSTANCE) - view.getHeight() - view.getTop() - statusBarHeight;

        } else {
            resultY = y;
        }

        return resultY;
    }



}